Skip to main content

Data Update

Making changes to existing data records to keep information up-to-date and relevant.


๐Ÿงฉ Overviewโ€‹

Data Update workflows are responsible for modifying existing records in the system. These updates may reflect changes in user inputs, process corrections, business rule adjustments, or synchronization with external systems.

This process must ensure:

  • Data integrity and auditability
  • Minimal disruption to related workflows
  • Controlled access and validation

๐Ÿ”„ Common Update Scenariosโ€‹

Use CaseDescription
Update patient contact infoPhone/email changed
Change billing statusMark as paid, refunded, or canceled
Modify test result valuesCorrection after review
Adjust user permissionsPromote or demote access roles

โš™๏ธ SQL-Based Update Exampleโ€‹

UPDATE patients
SET mobile = '9876543210', updated_at = NOW()
WHERE id = 105;

Always include updated_at and, optionally, updated_by to track changes.


๐Ÿงช Example: Status Transition for Lab Testโ€‹

Scenario:โ€‹

A lab test result moves from pending to approved after review.

UPDATE lab_results
SET status = 'approved', reviewed_by = 'Dr. Smith', reviewed_at = NOW()
WHERE id = 200 AND status = 'pending';

This ensures valid state transition (no redundant or invalid changes).


๐Ÿšฆ API Update Pattern (Express.js)โ€‹

router.put("/patients/:id", async (req, res) => {
const id = req.params.id;
const { name, mobile } = req.body;

await db.query(
"UPDATE patients SET name = ?, mobile = ?, updated_at = NOW() WHERE id = ?",
[name, mobile, id]
);

res.json({ status: "updated" });
});

โœ… Validation Considerationsโ€‹

  • Check that the record exists before updating
  • Validate incoming data types and formats
  • Enforce business rules (e.g., no downgrading paid status)
  • Prevent updates to restricted fields (e.g., ID, email after verification)

๐Ÿ” Access Controlโ€‹

FieldAccess Rule Example
is_admin flagOnly super admins can update
salaryOnly HR roles can modify
test_resultsOnly doctors or lab admins can edit

Use role-based control to restrict editing capabilities.


๐Ÿง  Best Practicesโ€‹

  • Use PATCH for partial updates, PUT for full object replacement
  • Always log what was changed, by whom, and when
  • Perform updates in transactions if multiple tables are involved
  • Add confirmation dialogs for UI-based changes
  • Allow undo where applicable (versioning, history tables)

๐Ÿงพ Auditing and Loggingโ€‹

Change Log Table Example:โ€‹

{
"table": "patients",
"record_id": 105,
"changed_by": "admin_user",
"timestamp": "2025-05-22T10:15:00Z",
"changes": {
"mobile": {
"from": "9123456789",
"to": "9876543210"
}
}
}

Store this log separately or in a JSON column in the main table.


๐Ÿ”„ UI Considerationsโ€‹

  • Inline editable fields for quick updates
  • Save & Cancel buttons for user control
  • Show change preview or summary before committing
  • Disable fields that should not be edited
  • Provide success/failure notifications

๐Ÿ“š Applications of Data Updateโ€‹

DomainUse Case
HealthcareUpdate diagnosis or doctor assigned
FinanceCorrect transaction amount or category
LogisticsUpdate delivery status or package location
HRModify employee records or job title

๐Ÿ”š Summaryโ€‹

The Data Update workflow ensures that information remains accurate, relevant, and traceable. It should be implemented with validation, access control, and logging to maintain system trustworthiness and regulatory compliance.